import groovy.json.JsonBuilder

def builder = new JsonBuilder()
def root = builder.students {
    student {
        studentName 'Jacke'
        studentId '1'

        // 嵌套到里面需要使用()而不能使用{}
        Marks(
            Subject1: 100,
            Subject2: 99,
            Subject3: 100
        )

        Sgow(1,2,3,4,5)
    }
    student1 {
        studentName 'Jacke2'
        studentId '2'

        // 嵌套到里面需要使用()而不能使用{}
        Marks(
            Subject1: 100,
            Subject2: 99,
            Subject3: 100
        )

        Sgow(1,2,3,4,5)
    }
}
println builder.toString()

def list = builder([1,2,3,4,5])
println builder.toString()


class Student{
    String name
}

def studentList = [new Student(name: 'Jackie'), new Student(name: "Mark"), new Student(name: "John")]
builder studentList, { student -> name student.name } //  { Student student -> name student.name } 两种都可以
println builder
